<?php

/*
 * This class is used for as Model for Metadata table 
 */

class Model_Metadata extends Model_Base {

    protected $_name = 'tbl_metadata';
    protected $_primaryKey = 'mtd_id';

    /**
     * Fetch an individual entry
     *
     * @param  int|string $key
     * @return null|Zend_Db_Table_Row_Abstract
     */
    public function fetchEntryByKey($key) {
        $select = $this->select()
                ->from(array('job' => 'tbl_metadata'))
                ->where('mtd_key = ?', $key);
        // see reasoning in fetchEntries() as to why we return only an array
        $data = $this->fetchRow($select);
        if (!empty($data)) {
            return $data->toArray();
        } else {
            return array();
        }
    }

    public function fetchall_meta() {
        $select = $this->select()
                ->from(array('job' => 'tbl_metadata'));
        // see reasoning in fetchEntries() as to why we return only an array
        $data = $this->fetchAll($select);
        if (!empty($data)) {
            return $data->toArray();
        } else {
            return array();
        }
    }

    /*     * *********Language Array****************** */

    public function getlanguageArray() {
        $languageModel = new Model_Language();
        $languageArray = $languageModel->language_fetchall();
        $languagedefaultArray = $languageModel->fetchType();
        $finalArray[''] = '';
        foreach ($languageArray as $com) {
            $finalArray[$com['lang_id']] = $com['lang_name'] . " [" . strtolower($com['lang_code']) . "]";
        }
        return $finalArray;
    }

    /*     * *********update data in meta table****************** */

    public function save_update_data($data) {
        /*         * *********update default language in language table************* */
        $lang_id = $data['DEFAULT_LANGUAGE'];
        $languageModel = new Model_Language();
        $languageArray = $languageModel->updatedefaultlang($lang_id);


        foreach ($data as $key => $value):
            $where = "'" . $key . "'";
            $data1 = array('mtd_value' => $value);
            $Update = $this->update($data1, 'mtd_key =' . $where);
        endforeach;
        //return true;
    }

}
